#include "stdafx.h"
void Application :: init_gorilla()
{
	string fontname("profont-prop");
	//string fontname("pixlimh");
    mGorilla		= new Gorilla	:: Silverback();
	int atlas_index = 0;

	mGorilla -> loadAtlas(fontname);
	gor_screen = mGorilla -> createScreen(viewport, fontname);
	gor_layer = gor_screen -> createLayer(0);

    Gorilla::Caption * gor_caption = gor_layer -> createCaption(atlas_index, 0, 0,
        string("The quick fox jumps over the lazy dog.1234567890'\"()[]{} !@#$%^&*~"));

    //StringVector dada;
    //dada.push_back("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut")  ;
    //dada.push_back("labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco")      ;
    //dada.push_back("laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in")     ;
    //dada.push_back("voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat") ;
    //dada.push_back("non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")                   ;
    //
    //multiline(dada);
    createBar(Vec2(200, 20), Vec2(150, 20));
}
void Application :: multiline(StringVector strs)
{
    for(size_t i = 0; i < strs.size(); i ++)
    {
        Gorilla :: Caption * c = gor_layer->createCaption(0, 20, 20 + i * 12, strs[i]);
        //c->size(c->width()*2.0,c->height()*2.0);
    }
}
bool Application :: frameRenderingQueued(const FrameEvent & evt)
{
	keyboard -> capture();
	mouse -> capture();
	timeSinceLastFrame = evt.timeSinceLastFrame;
	cam_node -> translate
	    (cam_node->getOrientation() *  translate * moving_speed * timeSinceLastFrame);
	assert(translate.length() <= 1.0f);

    bar.add_progress(timeSinceLastFrame);

	return ! stop;
}
void Application :: createBar(Vec2 origin, Vec2 dim)
{
    bar.frame = gor_layer -> createRectangle(origin,dim);
    bar.progress = gor_layer -> createRectangle(origin, dim);
    bar.frame->border(2.0f, bar.border);
    bar.frame->background_colour(bar.empty);
    bar.progress->background_colour(bar.filled);
}
void Application :: init_scene()
{
	cam_node = scmgr->getRootSceneNode()->createChildSceneNode("cam_node");
	cam_node -> attachObject(camera);
	//babar = NODE("babar");
	//Entity * e = ENTITY("bonome", "bonome.mesh");
	////LOGMSG(e->getName());
	//babar->attachObject(scmgr->getEntity("bonome"));
	//Entity * e2 = ENTITY("bonome2", "bonome.mesh");
 //       
 //   SceneNode * babar2 = NODE("babar2");
	//babar2->attachObject(scmgr->getEntity("bonome2"));
 //   babar2->setPosition(0,0,-10);

    SceneNode *
    light_node = scmgr -> getRootSceneNode()-> createChildSceneNode("light1");
    Light * light = scmgr -> createLight("light1");
	light -> setType(Light :: LT_POINT);
	light_node -> attachObject(light);
	light_node -> setPosition(3, 10, 3);

	light_node = scmgr -> getRootSceneNode()-> createChildSceneNode("light2");
    light = scmgr -> createLight("light2");
	light -> setType(Light :: LT_POINT);
	light_node -> attachObject(light);
	light_node -> setPosition(-3, 3, -3);

    cam_node->setPosition(0,0,3);
	viewport -> setBackgroundColour(ColourValue(0.1f, 0.1f, 0.1f));

    // sphere scene query
    size_t f, g, h, m = 3;

    f = 2;
    g = f*f;
    h = f*f*f;

    babar3.resize(h, NULL);

    for(size_t x = 0; x < f; ++ x)
        for(size_t y = 0; y < f; ++ y)
            for(size_t z = 0; z < f; ++ z)
            {
                size_t u = x + y*f + z*g;
//                Entity * a = ENTITY("bonome.mesh");
                Entity * a = scmgr->createEntity("DUDU"+TO_STR(u),"bonome.mesh");
                babar3[u] = scmgr->getRootSceneNode()->createChildSceneNode("DADA"+TO_STR(u));
                babar3[u] -> attachObject(a);
                babar3[u]->setPosition(m*x,m*y,m*z);
            }
    make_sphq();
    current_rayed = scmgr->getEntity("DUDU0");

    Procedural::

}
bool Application :: mousePressed	(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
    static_cast<Entity*>(babar3[0]->getAttachedObject(0))->setMaterialName("hover/hover");
    return true;
}
bool Application :: mouseReleased	(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
    static_cast<Entity*>(babar3[0]->getAttachedObject(0))->setMaterialName("hover/idle");

    return true;
}
